// Created by Windward Studios - no copyright is claimed. This code can be used in
// any manner by anyone for any reason. There is no copyright of any kind on it. You may
// use it in commercial products. You may change it without sharing those changes.
// We ask that you keep the "created by Windward Studios" in a comment at the top.

using System;
using System.Data.Common;

namespace net.windward.utils.ado.ODBC
{
	/// <summary>
	/// Represents an ODBC server.
	/// </summary>
    public class WrOdbcServer : IWrServer
	{
		/// <summary>
		/// The ODBC ADO.NET provider to access ODBC.
		/// </summary>
		protected readonly DbProviderFactory provider;
		/// <summary>
		/// The provider for the connection to this server.
		/// </summary>
		protected readonly string odbcProvider;
		private readonly string name;

		/// <summary>
		/// Create a ODBC server object.
		/// </summary>
		/// <param name="provider">The provider for this server.</param>
		/// <param name="odbcProvider">The provider for this connection.</param>
		/// <param name="name">The name of the server.</param>
		public WrOdbcServer(DbProviderFactory provider, string odbcProvider, string name)
		{
			this.provider = provider;
			this.odbcProvider = odbcProvider;
			this.name = name;
		}

		/// <summary>
		/// The name of the server.
		/// </summary>
		public string Name
		{
			get { return name; }
		}

		#region IWrServer Members

		/// <summary>
		/// All databases on this server. ODBC cannot enum databases and always returns an empty array.
		/// </summary>
		/// <param name="credentials">The user credentials to access the database.</param>
		/// <returns>All databases on this server.</returns>
		public IWrDatabase[] GetDatabases(WrCredentials credentials)
		{
			return new WrOdbcDatabase[0];
		}


		/// <summary>
		/// All databases on this server. ODBC cannot enum databases and always returns an empty array.
		/// </summary>
		/// <param name="connStr">The connection string to access the database.</param>
		/// <returns>All databases on this server.</returns>
		public IWrDatabase[] GetDatabases(string connStr)
		{
			return new WrOdbcDatabase[0];
		}

		#endregion

		/// <summary>
		/// Create a database object.
		/// </summary>
		/// <param name="database">The name of the database.</param>
		public virtual IWrDatabase CreateDatabase(string database)
		{
			return new WrOdbcDatabase(provider, odbcProvider, name, database);
		}

		/// <summary>
		/// Standard compare.
		/// </summary>
		/// <param name="obj">Object compared to.</param>
		/// <returns>-1, 0, or 1.</returns>
		public int CompareTo(object obj)
	    {
            WrOdbcServer db = obj as WrOdbcServer;
            if (db == null)
                return 1;
            return name.CompareTo(db.name);
        }
	}
}
